#!/bin/bash
set -e

# Recommended ulimit values for mongod or mongos
# See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
#
#limit fsize unlimited unlimited
#limit cpu unlimited unlimited
#limit as unlimited unlimited
#limit nofile 64000 64000
#limit rss unlimited unlimited
#limit nproc 32000 32000

data_dir=${MONGO_DATADIR:-"/srv/db"}
user=${MONGO_USER:-"mongodb"}

[ -d $data_dir ] || mkdir -p $data_dir
chown -R $user $data_dir

exec /sbin/setuser $user /usr/bin/mongod --dbpath $data_dir --journal --noprealloc --smallfiles
